<template>
  <div class="template_container">
    <div class="btn_box">
      <!-- <el-button type="primary" @click.stop="goBack">保存</el-button> -->
      <el-button @click.stop="goBack">返回</el-button>
    </div>
    <div class="assess_form swallow">
      <div class="form_title">XXXX医疗机构</div>
      <div class="form_name">高压氧治疗心理护理及安全告知书</div>
      <div class="form_patient_bar">
        <div
          v-for="(item, index) in patientStruct"
          :key="index"
          class="patient_info_item"
        >
          <div class="item_label">{{ item.label }}：</div>
          <div class="item_value">{{ currentPatient[item.key] }}</div>
        </div>
      </div>
      <el-form
        ref="assessForm"
        :model="selfFormData"
        :rules="rules"
        label-width="85px"
      >
        <div>
          <div class="form_assess_title">尊敬的患者（或家属）：</div>
          <div class="form_assess_item bold">
            根据病情和治疗需要，为了您能顺利完成治疗，确保安全，进入高压氧舱治疗前，请您认真仔细阅读以下内容并认真执行。
          </div>
          <div
            v-for="(item, index) in infoList"
            :key="index"
            class="form_assess_item"
          >
            {{ `${index + 1}.${item}` }}
          </div>
        </div>
        <div v-if="formType !== 'template'" class="assess_create_info right">
          <div class="create_info_item">
            <div class="item_label">医师签名：</div>
            <div class="item_value">{{ selfFormData.doctorSign }}</div>
          </div>
          <div class="create_info_item"></div>
          <div class="create_info_item">
            <div class="item_label">签名时间：</div>
            <div class="item_value">
              {{
                selfFormData.doctorSignTime &&
                moment(selfFormData.doctorSignTime).format(
                  "YYYY-MM-DD HH:mm:ss"
                )
              }}
            </div>
          </div>
        </div>
        <template v-if="formType !== 'template'">
          <div class="assess_create_info right">
            <div class="create_info_item">
              <div class="item_label">患方签名：</div>
              <!-- <div class="item_value">{{ selfFormData.signName }}</div> -->
              <el-input
                class="filter-item"
                v-model="selfFormData.signName"
                placeholder="请输入签名"
                clearable
                @change="signChange"
              />
            </div>
            <div class="create_info_item">
              <el-input
                class="filter-item"
                v-model="selfFormData.fingerprint"
                placeholder="请输入指纹"
                clearable
                @change="signChange"
              />
            </div>
            <div class="create_info_item">
              <div class="item_label">与患者关系：</div>
              <div class="item_value">
                <el-select
                  v-model="selfFormData.dicPatientRelation"
                  class="filter-item"
                  placeholder="请选择"
                  clearable
                >
                  <el-option
                    v-for="item in relationshipList"
                    :key="item.itemCode"
                    :label="item.itemName"
                    :value="item.itemCode"
                  />
                </el-select>
              </div>
            </div>
          </div>
          <div class="assess_create_info right">
            <div class="create_info_item">
              <div class="item_label">签名时间：</div>
              <div class="item_value">
                {{
                  selfFormData.signTime &&
                  moment(selfFormData.signTime).format("YYYY-MM-DD HH:mm:ss")
                }}
              </div>
            </div>
          </div>
        </template>

        <el-row style="text-align: center; padding-top: 20px">
          <el-button
            type="primary"
            @click.stop="submit"
            :loading="submitLoading"
          >
            保存
          </el-button>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>
import Cookies from "js-cookie";
import { GENDET_LIST, getLabel } from "./enums";
import moment from "moment";
import { dictionariesSearch } from "@/api/residentPhysician/cureBilling";
import { psychologicalAdd } from "@/api/therapistsSite/therapistsSite";
const defaultForm = {
  doctorSignTime: moment().valueOf(),
  doctorSign: "",
  signTime: "",
  signName: "",
  dicPatientRelation: undefined,
  fingerprint: undefined,
};
export default {
  name: "PsychologicalAssessment",
  data() {
    return {
      selfFormData: Object.assign({}, defaultForm),
      rules: {},
      formType: "edit",
      infoList: [
        "熟悉环境，了解高压氧环境中可能出现的不适反应和防治方法，消除紧张心理，积极配合治疗。",
        "入舱前排空大小便,以确保治疗能按时完成。",
        "严禁将火柴、打火机、收音机、助听器﹑手机、汽车钥匙、手表等可能引起火花的物品带入舱内。自己的衣裤，女性的胸罩、卫生巾、发胶、口红、指甲油等化妆品，有创口的油性敷料一律不准带入舱内。",
        "学会正确的捏鼻鼓气﹑吞咽咀嚼﹑张嘴巴等动作保持咽喉管通畅以防耳不适，升压过程中出现耳朵疼痛等不适请及时告知操舱工作人员。",
        "稳压过程中遇到不适及时与舱外医务人员沟通，听从医务人员的指导，配合医务人员进行相应处理。",
        "减压过程中不要憋气、不要用力咳嗽，保持正常呼吸，此过程舱内温度会有所下降，要注意保暖。",
        "出舱后有任何不适及时告知医务人员。",
        "为确保医疗安全，出现以下情况可能终止治疗，并提早出舱，敬请谅解:气管切开的病人﹔烦躁不安的病人﹔耳痛不适于的病人﹔舱内大小便不能控制的病人﹔其他紧急情况出现的病人。",
        "储物箱物品使用后及时清理,贵重物品自行保管。",
        "注意安全，对认知功能障碍﹑四肢活动障碍﹑头晕、乏力等患者需全程陪护及接送，平车、轮椅患者注意使用防护栏、刹车，避免坠床﹑跌倒。",
      ],
      relationshipList: [],
      submitLoading: false,
    };
  },
  computed: {
    patientStruct() {
      return [
        {
          label: "姓名",
          key: "patientName",
        },
        {
          label: "性别",
          key: "genderName",
        },
        {
          label: "年龄",
          key: "age",
        },
        {
          label: "科室",
          key: "departmentName",
        },
        {
          label: "门诊号",
          key: "outpatientNum",
        },
      ];
    },
    currentPatient() {
      try {
        const info = JSON.parse(Cookies.get("currentPatient"));
        return info
          ? {
              ...info,
              genderName: getLabel(info.gender, GENDET_LIST),
            }
          : {};
      } catch (res) {
        return {};
      }
    },
  },
  created() {
    const userInfo = this.$store.state.user.user;
    this.selfFormData.doctorSign = userInfo.realname;
    dictionariesSearch({
      dicCode: "dicPatientRelation",
    }).then((res) => {
      const { content } = res;
      if (
        Array.isArray(content) &&
        content.length > 0 &&
        Array.isArray(content[0].itemList) &&
        content[0].itemList.length > 0
      ) {
        this.relationshipList = content[0].itemList;
      }
    });
  },
  methods: {
    moment,
    goBack() {
      this.$router.back();
    },
    getFormData() {
      return new Promise((resolve, reject) => {
        this.$refs.assessForm.validate((valid) => {
          if (valid) {
            resolve({
              ...this.selfFormData,
            });
          } else {
            reject("存在未通过表单校验的数据");
            return false;
          }
        });
      });
    },
    submit() {
      this.getFormData().then((data) => {
        this.submitLoading = true;
        psychologicalAdd({
          ...data,
          reservationId: this.currentPatient.reservationId,
        })
          .then(() => {
            this.$notify({
              title: "保存成功",
              type: "success",
              duration: 1500,
            });
            this.goBack();
          })
          .finally(() => {
            this.submitLoading = false;
          });
      });
    },
    signChange() {
      this.selfFormData.signTime = moment().valueOf();
    },
  },
};
</script>

<style lang="scss" scoped>
@import url("~@/views/assessSys/templates/style.scss");
@import url("~@/views/assessSys/components/style.scss");

.form_assess_item .blod {
  font-weight: bold;
  text-indent: 2rem;
}

.assess_create_info {
  align-items: center;
}

.create_info_item {
  align-items: center;
  flex: 1;
  padding: 5px 10px;
}
</style>
